const state = {
  showTopActive: true,
  subMenu: [],
}

// 过滤掉noMenuPaged页面
const mapdata = function (list = [], arr = []) {
  for (let me of list) {
    if (me.noMenuPage) continue;
    let node = {
      ...me,
      // 这里要保证children为空数组
      children: [],
      open: false
    };
    arr.push(node)
    // 这里把子级放到空数组里
    if (me.children && me.children.length) {
      mapdata(me.children, node.children);
    }
  }
  return arr;
};

const mutations = {
  setSubMenu(state, list) {
    state.subMenu = mapdata(list)
  },
  setTopActive(state, bool) {
    state.showTopActive = bool
  }
}

const actions = {
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}